package TwoArray;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author feng
 * @Date 2021/7/22 8:40
 * 利用线程制作定时器,
 *     eg:线程睡觉，线程终止
 */
public class Thread01 extends Thread {
    private boolean flag = true;

    @Override
    public void run() {
        int time = 10;
        while (flag) {
            Date date = new Date();
            System.out.println("倒计时" + new SimpleDateFormat("HH:mm:ss").format(date));
            try {
                Thread.sleep(1000);
                --time;
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            if (time <= 0) {
                stopThread();
            }
        }

    }

    boolean stopThread() {
        flag = false;
        return flag;
    }


}

class A {
    public static void main(String[] args) {
        Thread01 thread01 = new Thread01();
        thread01.start();
    }

}